package com.rainy.micservice.provider.service;

import com.rainy.micservice.provider.domain.App;
import com.rainy.micservice.provider.mapper.ds.AppMapper;
import com.rainy.micservice.provider.mapper.ds1.AppMapper1;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

@Service
public class AppService{

    @Autowired
    AppMapper appMapper;

    @Autowired
    AppMapper1 appMapper1;

    @Resource
    RedisTemplate<Object,Object> redisTemplate;

    private Log logger = LogFactory.getLog(AppService.class);

    @Transactional
    public App findById() {

        App o = new App();
        o.setId("1");
        App app = appMapper.findById(o);
        return app;

    }
    @Transactional
    public boolean delAppById(String id) {

        App o = new App();
        o.setId("2");
        boolean flag = appMapper.delAppById(o);

        return flag;

    }
    @Transactional
    public List<App> findAll() {

        List<App> apps = appMapper1.findAll();

        return apps;

    }

    @Transactional
    public String insertApp(String name) {

        App o = new App();
        o.setId("8");
        o.setName(name);
        o.setCreated(new Timestamp(System.currentTimeMillis()));

        App o1 = new App();
        o1.setId("8");
        o1.setName(name);
        o1.setCreated(new Timestamp(System.currentTimeMillis()));
        appMapper.insertApp(o);
        appMapper1.insertApp(o1);
        return "8";

    }
    @Transactional
    public boolean updateAppNameById(String id, String name) {

        App o = new App();
        o.setId(id);
        o.setName(name);
        boolean flag = appMapper.updateAppNameById(o);
        return flag;

    }

}
